package com.ruoyi.mes.service.impl;

import java.util.List;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.mes.utils.CodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mes.mapper.ProMaterielMapper;
import com.ruoyi.mes.domain.ProMateriel;
import com.ruoyi.mes.service.IProMaterielService;

/**
 * 产品物料Service业务层处理
 * 
 * @author CFL
 * @date 2024-04-28
 */
@Service
public class ProMaterielServiceImpl implements IProMaterielService 
{
    @Autowired
    private ProMaterielMapper proMaterielMapper;

    /**
     * 查询产品物料
     * 
     * @param id 产品物料主键
     * @return 产品物料
     */
    @Override
    public ProMateriel selectProMaterielById(Long id)
    {
        return proMaterielMapper.selectProMaterielById(id);
    }

    /**
     * 查询产品物料列表
     * 
     * @param proMateriel 产品物料
     * @return 产品物料
     */
    @Override
    public List<ProMateriel> selectProMaterielList(ProMateriel proMateriel)
    {
        return proMaterielMapper.selectProMaterielList(proMateriel);
    }

    /**
     * 新增产品物料
     * 
     * @param proMateriel 产品物料
     * @return 结果
     */
    @Override
    public int insertProMateriel(ProMateriel proMateriel)
    {
        BaseController baseController = new BaseController();
        String username = baseController.getUsername();
        proMateriel.setCreatedBy(username);
        proMateriel.setCreatedTime(DateUtils.getNowDate());
        String matSn = CodeUtils.MatCodeCreat();
        proMateriel.setMatSn(matSn);
        return proMaterielMapper.insertProMateriel(proMateriel);
    }

    /**
     * 修改产品物料
     * 
     * @param proMateriel 产品物料
     * @return 结果
     */
    @Override
    public int updateProMateriel(ProMateriel proMateriel)
    {
        BaseController baseController = new BaseController();
        String username = baseController.getUsername();
        proMateriel.setCreatedBy(username);
        proMateriel.setCreatedTime(DateUtils.getNowDate());
        return proMaterielMapper.updateProMateriel(proMateriel);
    }

    /**
     * 批量删除产品物料
     * 
     * @param ids 需要删除的产品物料主键
     * @return 结果
     */
    @Override
    public int deleteProMaterielByIds(Long[] ids)
    {
        return proMaterielMapper.deleteProMaterielByIds(ids);
    }

    /**
     * 删除产品物料信息
     * 
     * @param id 产品物料主键
     * @return 结果
     */
    @Override
    public int deleteProMaterielById(Long id)
    {
        return proMaterielMapper.deleteProMaterielById(id);
    }
}
